<?php
/**
* @version $Id: registration.html.php 10002 2008-02-08 10:56:57Z willebil $
* @package Joomla
* @subpackage Users
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
* @package Joomla
* @subpackage Users
*/
class HTML_registration {
	function lostPassForm($option) {
		// used for spoof hardening
		$validate = josSpoofValue();
		?>
		<div class="w_title_website">
			<div class="w_show_title_website"><?php echo _PROMPT_PASSWORD; ?></div>
			<div class="clearfix"></div>
			<div class="w_show_content">
				<form action="index.php" method="post">
				<table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">
				<tr>
					<td width="30%" align="right"></td>
					<td>
						<?php echo _NEW_PASS_DESC; ?>
					</td>
				</tr>
				<tr>
					<td width="30%" align="right">
						<?php echo _PROMPT_UNAME; ?>
					</td>
					<td>
						<input type="text" name="checkusername" class="inputbox" size="40" maxlength="25" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<?php echo _PROMPT_EMAIL; ?>
					</td>
					<td>
						<input type="text" name="confirmEmail" class="inputbox" size="40" />
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
						<input type="submit" class="button_submit button-css3" value="<?php echo _BUTTON_SEND_PASS; ?>" />
					</td>
				</tr>
				</table>
				
				<input type="hidden" name="option" value="<?php echo $option;?>" />
				<input type="hidden" name="task" value="sendNewPass" /> 
				<input type="hidden" name="<?php echo $validate; ?>" value="1" />
				</form>
			</div>
		</div>	
		<?php
	}

	function registerForm($option, $useractivation, &$listCity) {
		global $mosConfig_live_site, $database;
		// used for spoof hardening
		$validate = josSpoofValue();
		mosCommonHTML::loadOverlib();
		mosCommonHTML::loadCalendar();
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site; ?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<link rel="stylesheet" href="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.css" type="text/css" />
		<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript">
		function delete_extra_options (selobj, size)
		{
			while (selobj . options . length > size)
				selobj . options [selobj . options . length - 1] = null;
		}
		
		function update_item_list ()
		{
			var cat_selobj = document . mosForm . city_id;
			var item_selobj = document . mosForm . district_id;
			var choice = cat_selobj . options [cat_selobj . selectedIndex] . value;
			<?php
			for ($i=0; $i<count($listCity); $i++){
				?>
				if (choice == <?php echo $listCity[$i]->id;?>)
				{
					<?php
					$sql = "select count(*) from #__district where published=1 and city_id=".$listCity[$i]->id;
					$database->setQuery($sql);
					$total = $database->loadResult();
					$sql = "select * from #__district where published=1 and city_id=".$listCity[$i]->id." order by title asc, id desc";
					$database->setQuery($sql);
					$listDistrict = $database->loadObjectList();
					for ($j=0; $j<count($listDistrict); $j++){
					?>
					item_selobj . options [<?php echo $j;?>] = new Option ("<?php echo $listDistrict[$j]->title;?>","<?php echo $listDistrict[$j]->id;?>");
					<?php
					}
					?>
					delete_extra_options (item_selobj, <?php echo $total;?>);
				}
				<?php
			}
			?>
		}
		function submitbutton_reg() {
			var form = document.mosForm;
			var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");

			// do field validation
			if (form.name.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_NAME) );?>" );
				$('input[name=name]').focus();
			} else if (form.username.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_UNAME) );?>" );
				$('input[name=username]').focus();
			} else if (r.exec(form.username.value) || form.username.value.length < 3) {
				alert( "<?php printf( addslashes( html_entity_decode(_VALID_AZ09_USER) ), addslashes( html_entity_decode(_PROMPT_UNAME) ), 2 );?>" );
				$('input[name=username]').focus();
			} else if (form.email.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_MAIL) );?>" );
				$('input[name=email]').focus();
			} else if (form.password.value.length < 6) {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_PASS) );?>" );
				$('input[name=password]').focus();
			} else if (form.password2.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_VPASS1) );?>" );
				$('input[name=password2]').focus();
			} else if ((form.password.value != "") && (form.password.value != form.password2.value)){
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_VPASS2) );?>" );
				$('input[name=password]').focus();
			} else if (r.exec(form.password.value)) {
				alert( "<?php printf( addslashes( html_entity_decode(_VALID_AZ09) ), addslashes( html_entity_decode(_REGISTER_PASS) ), 6 );?>" );
				$('input[name=password]').focus();
			} else if (form.address.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_ADDRESS) );?>" );
				$('input[name=address]').focus();
			} else if (form.city_id.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_CITY) );?>" );
				$('select[name=city_id]').select();
			} else if (form.mobile.value == "") {
				alert( "<?php echo addslashes( html_entity_decode(_REGWARN_MOBILE) );?>" );
				$('input[name=mobile]').focus();
			} else {
				form.submit();
			}
		}
	    $(document).ready(function() {
		    //Change user register
	    	$('#user_class').change(function(){
	    		var userClassVal = $('#user_class').val();
        		if (userClassVal == 1) $('.user_normal').hide();
        		else $('.user_normal').show();
        	});
        	//Check file uploads
	    	$('#myFile').change(function() {
			  //alert(this.files[0].size);
			  sizeFile = this.files[0].size;
			  if (sizeFile > 51200){
				  alert( "Dung lượng file lớn hơn 50KB ! Vui lòng chọn file ảnh nhỏ hơn để việc upload lên server được thực hiện tốt !" );
				  $("#myFile").replaceWith('<input type="file" size="34" name="img" id="myFile" title="Avatar/Logo" class="inputbox">');
			  }
			});
			//Load editor
	    	$(function()
    		{
    			$('#wysiwyg').wysiwyg();
    		});
	    });
		</script>
		<div class="w_title_website">
			<div class="w_show_title_website"><?php echo _REGISTER_TITLE; ?></div>
			<div class="clearfix"></div>
			<div class="w_show_content border-shadow" style="margin-bottom:5px;">
				<form action="index.php" method="post" name="mosForm" enctype="multipart/form-data">
				<table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">
				<tr>
					<td width="30%" align="right"></td>
					<td align="left"><?php echo _REGISTER_REQUIRED; ?></td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_CLASS; ?></b>
					</td>
					<td align="left">
						<select size="1" name="user_class" id="user_class" title="Chọn" class="inputbox" style="width:180px;">
							<option value="0">Thành viên tự do</option>
							<option value="1">Nhà cung cấp sản phẩm</option>
						</select>
					</td>
				</tr>
				<tr>
					<td width="20%" align="right">
						<b><?php echo _REGISTER_NAME; ?></b> <font color="red">*</font>
					</td>
				  	<td align="left">
				  		<input type="text" name="name" size="40" value="" class="inputbox" maxlength="50" />
				  		<div class="form_text_warning">
							- Nếu bạn là nhà cung cấp thì nên đặt tên theo tên công ty. ( VD: Siêu thị điện thoại ).<br />
							- Nếu bạn không phải là nhà cung cấp thì đặt tên theo tên của bạn. ( VD: Nguyễn Văn A ).
						</div>
				  	</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_UNAME; ?></b> <font color="red">*</font>
					</td>
					<td align="left">
						<input type="text" name="username" size="40" value="" class="inputbox" maxlength="25" />
						<div class="form_text_warning">
							- Tên truy cập phải có ít nhất 4 ký tự (chữ, số, ký tự _, viết liền, không dấu).<br>
<!--							- Nếu đăng ký gian hàng, xin hãy lấy tên phù hợp với Công ty của bạn.<br>-->
<!--							- Ví dụ: Công ty TNHH Trần Anh thì nên lấy tên "trananh"<br>-->
<!--							- Tên gian hàng sẽ được hiển thị http://www.vatgia.com/trananh-->
						</div>
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_PASS; ?></b> <font color="red">*</font>
					</td>
				  	<td align="left">
				  		<input class="inputbox" type="password" name="password" size="40" value="" />
				  		<div class="form_text_warning">
							- Mật khẩu phải có ít nhất 6 ký tự.<br>
<!--							- Gần đây có nhiều trường hợp bị chiếm đoạt tài khoản sử dụng vào mục đích <span class="form_errorMsg">vi phạm pháp luật</span>. Do vậy:<br>-->
<!--							- Bạn không được đặt mật khẩu quá đơn giản, dễ đoán (vd: <span class="form_errorMsg">123456, vatgia,...</span>)<br>-->
<!--							- Không được trùng với Tên truy cập, Email, Điện thoại cố định, Điện thoại di động,...-->
						</div>
				  	</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_VPASS; ?></b> <font color="red">*</font>
					</td>
					<td align="left">
						<input class="inputbox" type="password" name="password2" size="40" value="" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_EMAIL; ?></b> <font color="red">*</font>
					</td>
					<td align="left">
						<input type="text" name="email" size="40" value="" class="inputbox" maxlength="100" />
						<div class="form_text_warning">Email bạn nhập phải tồn tại, chúng tôi sẽ gửi mã kích hoạt vào email đó.</div>
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_ADDRESS; ?></b> <font color="red">*</font>
					</td>
					<td align="left">
						<input type="text" name="address" size="40" value="" class="inputbox" maxlength="25" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_CITY_ID; ?></b> <font color="red">*</font>
					</td>
					<td align="left">
						<select onChange="update_item_list();" size="1" name="city_id" id="city_id" title="Chọn" class="inputbox" style="width:150px;">
							<option value="">--[Chọn]--</option>
							<?php
							for ($i=0; $i<count($listCity); $i++){
								echo "<option value='".$listCity[$i]->id."'>".$listCity[$i]->title."</option>";
							}
							?> 
						</select>
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_DISTRICT_ID; ?></b>
					</td>
					<td align="left">
						<select onchange="" size="1" name="district_id" id="district_id" title="Chọn" class="inputbox" style="width:150px;">
							<option value="">--[Chọn]--</option>
						</select>
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_MOBILE; ?></b> <font color="red">*</font>
					</td>
					<td align="left">
						<input type="text" name="mobile" size="40" value="" class="inputbox" maxlength="25" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_IMG; ?></b>
						
					</td>
					<td align="left">
						<input type="file" size="34" name="img" id="myFile" title="Avatar/Logo" class="inputbox">
						<div class="form_text_warning">(Ảnh không được quá <span style="color:#FF0000">50 KB</span> và có phần mở rộng là: <span style="color:#FF0000">.gif, .jpg, .png</span>)<br>Nếu đăng ký gian hàng nên lấy Logo của Công ty.</div>
					</td>
				</tr>
				<tr class="user_normal">
					<td align="right">
						<b><?php echo _REGISTER_SEX; ?></b>
					</td>
					<td align="left">
						<select onchange="" size="1" name="sex" id="sex" title="Chọn" class="inputbox" style="width:80px;">
							<option value="1">Nam</option>
							<option value="0">Nữ</option>
						</select>
					</td>
				</tr>
				<tr class="user_normal">
					<td align="right">
						<b><?php echo _REGISTER_BIRTHDAY; ?></b>
					</td>
					<td align="left">
						<input class="inputbox" type="text" name="birthday" id="birthday" size="25" style="width:150px;" value="" />
						<input name="reset" type="reset" class="button" onclick="return showCalendar('birthday', 'y-mm-dd');" value="..." />
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_YAHOO; ?></b>
					</td>
					<td align="left">
						<input type="text" name="yahoo" size="40" value="" class="inputbox" maxlength="25" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_SKYPE; ?></b>
					</td>
					<td align="left">
						<input type="text" name="skype" size="40" value="" class="inputbox" maxlength="25" />
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_WEBSITE; ?></b>
					</td>
					<td align="left">
						<input type="text" name="website" size="40" value="http://" class="inputbox" maxlength="25" />
						<div class="form_text_warning">
							- Địa chỉ website nếu có nhập đầy đủ như ( <b style="color:red;">http://google.com.vn</b> ).<br>
						</div>
					</td>
				</tr>
				<tr>
					<td align="right">
						<b><?php echo _REGISTER_ABOUTS; ?></b>
					</td>
					<td align="left">
						<textarea name="content" id="wysiwyg" rows="5" cols="63"></textarea>
					</td>
				</tr>
				<tr>
					<td align="right">
					</td>
					<td align="left">
						<input type="button" value="<?php echo _BUTTON_SEND_REG; ?>" class="button_submit button-css3" onclick="submitbutton_reg()" />
						<input type="button" value="<?php echo _BUTTON_RESET; ?>" class="button_submit button-css3" />
					</td>
				</tr>
				<tr>
					  <td colspan="2">
					  </td>
				</tr>
				<tr>
					<td colspan=2>
					</td>
				</tr>
				</table>
				<input type="hidden" name="id" value="0" />
				<input type="hidden" name="gid" value="0" />
				<input type="hidden" name="useractivation" value="<?php echo $useractivation;?>" />
				<input type="hidden" name="option" value="<?php echo $option; ?>" />
				<input type="hidden" name="task" value="saveRegistration" />
				<input type="hidden" name="<?php echo $validate; ?>" value="1" />
				</form>
			</div>
		</div>
		<?php
	}
}
?>